<template>
  <div class="p-2">
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-button>批量操作
            <Icon icon="mdi:chevron-down"></Icon>
          </a-button>
        </a-dropdown>
        <a-space>
          <a-input style="border-radius: 5px;" placeholder="镜像名称"/>
          <a-input style="border-radius: 5px;" placeholder="镜像地址"/>
          <a-input style="border-radius: 5px;" placeholder="分组"/>
          <a-button type="primary" style="border-radius: 5px;" @click="handleSuccess">搜索</a-button>
          <a-button type="primary" shape="round" @click="handleSuccess" preIcon="ant-design:plus-outlined">新增</a-button>
        </a-space>
      </template>
      <template #bodyCell = "{ column, record }">
        <!-- 对镜像状态做枚举值的设定,分别有待提交,待审核,审核通过,审核不通过 -->
        <a v-if = "column.dataIndex == 'status' ">
          <a-badge v-if="record.imageStatusType == 'default' " status="default" color="blue" :text="record.imageStatusName"/>
          <a-badge v-else-if="record.imageStatusType == 'waiting' " status="processing" color="yellow" :text="record.imageStatusName"/>
          <a-badge v-else-if="record.imageStatusType == 'pass' " status="processing" color="green" :text="record.imageStatusName"/>
          <a-badge v-else-if="record.imageStatusType == 'reject' " color="red" :text="record.imageStatusName"/>
        </a>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <!--- 改成用几个醒目的按钮 --->
        <a-space>
          <a-button type = "primary" size="small" shape = "round" @click="handlePass(record)">通过</a-button>
          <a-button type = "danger"  size="small" shape = "round" @click="handleReject(record)">不通过</a-button>
          <a-button type = "primary"  size="small" shape = "round" @click="check(record)">查看详情</a-button>
        </a-space>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <VmImageModal ref="registerModal" @success="handleSuccess"></VmImageModal>
  </div>
</template>

<script lang="ts" name="vm-vmImage" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './VmImage.data';
  import { listToReview,reviewPass,reviewReject } from './VmImage.api';
  import VmImageModal from './components/VmImageModal.vue';

  // 审核相关函数
  async function handlePass(record) {
    await reviewPass({ id: record.id }, handleSuccess);
  }
  async function handleReject(record) {
    await reviewReject({ id: record.id }, handleSuccess);
  }

  // 镜像数据弹窗
  const queryParam = reactive<any>({});
  const registerModal = ref();
  function check(record) {
    // 1. 打开弹窗,不可编辑状态,下方设置两个按钮
    console.log(record)
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }
  //注册table数据
  const {  tableContext } = useListPage({
    tableProps: {
      title: '待审核镜像',
      api: listToReview,
      columns,
      canResize:true,
      useSearchForm: false,
      actionColumn: {
        width: 300,
        resizable: true,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
  });
  const [registerTable, { reload }, { selectedRowKeys }] = tableContext;
   
  
   
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
   
   

  
  /**
   * 重置
   */
  // function searchReset() {
  //  formRef.value.resetFields();
  //  selectedRowKeys.value = [];
  //  //刷新数据
  //  reload();
  //}
  
  defineExpose({
    handlePass,
    handleReject
  });


</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
